
import java.awt.Point;

public class LocalAligner extends GlobalAligner {

	int matrixMax = 0;
	Point matrixMaxPoint = new Point(0, 0);

	protected void getLocalPath(int x, int y) {
		int top = matrix[x][y - 1] + penaltyFunction.gapPenalty(x, y);
		int left = matrix[x - 1][y] + penaltyFunction.gapPenalty(x, y);
		int align = matrix[x - 1][y - 1] + scoreFunction.score(matrix, x, y);
		int max = Math.max(Math.max(top, left), align);
		max = Math.max(max, 0);
		matrix[x][y] = max;

		// higher
		if (max == left) {
			path[x][y] = new Point(x - 1, y);
		} else if (max == align) {
			path[x][y] = new Point(x - 1, y - 1);
		} else if (max == top) {
			path[x][y] = new Point(x, y - 1);
		} else {
			path[x][y] = null;
		}

		if (max >= matrixMax) {
			matrixMax = max;
			matrixMaxPoint = new Point(x, y);
		}

	}

	protected Point getTrackBackStartPoint() {
		return matrixMaxPoint;
	}

	protected boolean isTraceBackEnd(Point point) {
		if (point == null) {
			return true;
		}
		if (matrix[point.x][point.y] == 0) {
			return true;
		}
		return false;
	}

}
